using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Dungeon_Dive
{
    /// <summary>
    /// This is a simple game screen. Subclass to create different screens for a game.
    /// </summary>
    public class GameScreen : DrawableGameComponent
    {
        protected Game1 parentGame;
        protected List<GameComponent> components;
        protected List<GameComponent> Components { get { return components; } }
        private Log log;

        public GameScreen(Game1 game) : base(game)
        {
            parentGame = game;
            components = new List<GameComponent>();
            Hide();
        }

        /// <summary>
        /// Initialize screen and all its components.
        /// </summary>
        public override void Initialize()
        {
            log = (Log)parentGame.Services.GetService(typeof(Log));
            log.Write("GameScreen.Init()");
            foreach (GameComponent child in Components)
            {
                child.Initialize();
            }
            base.Initialize();
        }

        protected override void LoadContent()
        {
            log.Write("GameScreen.LoadContent()");
            base.LoadContent();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            foreach (GameComponent gc in components)
            {
                if (gc.Enabled)
                {
                    gc.Update(gameTime);
                }
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            foreach (GameComponent gc in components)
            {
                DrawableGameComponent dgc = gc as DrawableGameComponent;
                if (dgc != null && dgc.Visible)
                {
                    dgc.Draw(gameTime);
                }
            }
            base.Draw(gameTime);
        }

        public virtual bool Show()
        {
            Enabled = true;
            Visible = true;
            return true;    // I don't think we actually use this for anything currently
        }

        public virtual bool Hide()
        {
            Enabled = false;
            Visible = false;
            return true;
        }
    }
}